<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Promise</title>
</head>
<body>

	<h1>Promise</h1>
	<div><textarea id="output" style="height: 200px; width:500px;"></textarea></div>
	<script type="text/javascript">
	
		var log = function(msg){
			var output = document.querySelector('#output');
			output.value = output.value + msg + '\n';
			console.log(msg);
		};
		
		var p1 = new Promise(function (resolve, reject) {
		    setTimeout(resolve, 500, 'P1');
		});
		var p2 = new Promise(function (resolve, reject) {
		    setTimeout(resolve, 600, 'P2');
		});
		// 同时执行p1和p2，并在它们都完成后执行then:
		Promise.all([p1, p2]).then(function (results) {
		    log(results); // 获得一个Array: ['P1', 'P2']
		});
	</script>
</body>
</html>